import axios from '@/utils/axios';
/*!
 * 栏目管理 通用（请求）方法
 *  
 * 作者：田琳
 * Copyright (c) 2019/12/10
 * 
 */

/**
 * @method headingAdd 新增栏目接口
 * @param {object} data 栏目模块新增弹框里的form对象
 * @return axios
 */
export const headingAdd = (data) => {
    return axios({
      url: '/cms/heading',
      method: 'post',
      data
    })
}
/**
 * @method headingSearch 栏目树搜索接口
 * @param {string} 模糊搜索值headingName
 * @return axios
 */
export const headingSearch = (val) => {
    // return axios({
    //   url: '/cms/heading?headingName=' + val,
    //   method: 'get'
    // })
    return axios.get('/cms/heading', {
        params: {
            headingName: val
        }
	})
} 
/**
 * @method headingTree 组织树渲染和组织树搜索接口
 * @param {string} id 获取组织树id字段
 * @return axios
 */
export const headingTree = (id) => {
    if(!id){
        return axios({
            url: '/cms/heading',
            method: 'get'
        })
    }else{
        return axios({
            url: `/cms/heading?headingId=${id}`,
            method: 'get'
        })
    }
}
//栏目table列表
export const headingTable = (idTable,currentPage,pageSize,name) => {
    if(!name){
        return axios({
            url: '/cms/'+idTable+'/heading/'+currentPage+'/'+pageSize,
            method: 'get'
        })
    }else{
        return axios({
            url: '/cms/'+idTable+'/heading/'+currentPage+'/'+pageSize+'?headingName='+name,
            method: 'get'
        })
    }
}
//表格获取详情
export const getHeadingEdit = (id) => {
    return axios({
      url: `/cms/heading/${id}`,
      method: 'get'
    })
}
/**
 * @method headingDelete 栏目表格单条数据删除接口
 * @param {string} id 获取表格单挑数据id字段
 * @return axios
 */
export const headingDelete = (id) => {
    return axios({
      url: `/cms/heading/${id}`,
      method: 'delete'
    })
}
/**
 * @method headingPut 栏目表格单条数据修改接口
 * @param {object} data 栏目模块修改弹框里的form对象
 * @return axios
 */
export const headingPut = (data) => {
    return axios({
      url: '/cms/heading',
      method: 'put',
      data
    })
}

/**
 * @method eosDict 字典查询栏目内容模板接口
 * @param {string} id 字典查询栏目id字段
 * @return axios
 */
export const eosDict = (id) => {
    return axios({
      url: '/base/dict/children/'+id,
      method: 'get'
    })
}

/**
 * @method getTemplate 字典查询栏目内容模板接口
 * @param {string} id 字典查询栏目id字段
 * @return axios
 */
export const getTemplate = () => {
    return axios({
      url: '/cms/template/0/0',
      method: 'get'
    })
}
/**
 * @method uploadByBusiness 图片上传接口
 * @param {object} data 图片上传栏目名称等参数
 * @return axios
 */
export const uploadByBusiness = (data) => {
    return axios({
      url: '/attachment/uploadByBusiness',
      method: 'post',
      data
    })
}